package com.qizhou.compiler.enitity.func

import com.qizhou.compiler.FilterHttpCodeClassType
import com.qizhou.compiler.OnlyFilterHttpCodeClassType
import com.qizhou.compiler.SimpleDataSourceClassType
import com.qizhou.compiler.enitity.FuncBuilder
import com.qizhou.compiler.enitity.ReposityMothed
import com.squareup.kotlinpoet.FunSpec

class AutoApiFunc(private val mReposityMothed: ReposityMothed) : FuncBuilder(mReposityMothed) {

    override fun addStatement(funcBuilder: FunSpec.Builder) {

        val paramsStringBuilder = StringBuilder()
        reposityMothed.parameters.forEach {
            paramsStringBuilder.append(it.name).append(",")
        }

        //filterFunClass filterCommonParseModel
        if (reposityMothed.filterFunClass!=null) {

            funcBuilder.addStatement(" return %T{ \n apiService.%L(%L)"
                    + ".%T()" + " \n}.startFetchData()"
                    , SimpleDataSourceClassType, reposityMothed.methodName
                    , paramsStringBuilder.toString().dropLast(1)
                    , reposityMothed.filterFunClass!!)

        } else {
            funcBuilder.addStatement(" return %T{ \n apiService.%L(%L)"
                    + " \n}.startFetchData()"
                    , SimpleDataSourceClassType, reposityMothed.methodName
                    , paramsStringBuilder.toString().dropLast(1))
        }
    }
}